#pragma once
#include "IOnvifToolClass.h"
#include <vector>
#include "utils.h"
#include "stdsoap2.h"
#include "soapStub.h"
using std::vector;

#ifdef _WIN64
#ifndef WIN32
#define WIN32
#endif
#endif
#ifdef _WIN32
#ifndef WIN32
#define WIN32
#endif
#endif

#define MUTICAST_ADDR "239.255.255.250"

class onvifTool : public IOnvifTool
{
public:
    onvifTool();
    virtual ~onvifTool();

public:
    virtual optional<string> init() override;
    virtual void printLog(logCB cb, void *pUserData) override;
    virtual void setTimeOut(int timeOut_ = 15) override;
    virtual optional<string> discoverDevice(string &responseJson) override;
    virtual optional<string> listenHello(listenCB cb, void *pUserData) override;
    virtual optional<string> stopListenHello() override;
    virtual optional<string> listenBye(listenCB cb, void *pUserData) override;
    virtual optional<string> stopListenBye() override;
    virtual optional<string> getDeviceInformation(string &responseJson,
                                                  const char *deviceXAddr,
                                                  const char *userName,
                                                  const char *password) override;
    virtual optional<string> getServiceCapabilities(string &responseJson,
                                                    const char *deviceXAddr) override;
    virtual optional<string> getServices(string &responseJson,
                                         const char *deviceXAddr) override;
    virtual optional<string> getDNS(string &responseJson,
                                    const char *deviceXAddr,
                                    const char *userName,
                                    const char *password) override;
    virtual optional<string> getDynamicDNS(string &responseJson,
                                           const char *deviceXAddr,
                                           const char *userName,
                                           const char *password) override;
    virtual optional<string> getEndpointReference(string &responseJson,
                                                  const char *deviceXAddr) override;
    virtual optional<string> getGeoLocation(string &responseJson,
                                            const char *deviceXAddr,
                                            const char *userName,
                                            const char *password) override;
    virtual optional<string> getNetworkDefaultGateway(string &responseJson,
                                                      const char *deviceXAddr,
                                                      const char *userName,
                                                      const char *password) override;
    virtual optional<string> getNetworkInterfaces(string &responseJson,
                                                  const char *deviceXAddr,
                                                  const char *userName,
                                                  const char *password) override;
    virtual optional<string> getNetworkProtocols(string &responseJson,
                                                 const char *deviceXAddr,
                                                 const char *userName,
                                                 const char *password) override;
    virtual optional<string> getHostname(string &responseJson,
                                         const char *deviceXAddr) override;
    virtual optional<string> getRemoteUser(string &responseJson,
                                           const char *deviceXAddr,
                                           const char *userName,
                                           const char *password) override;
    virtual optional<string> getScopes(string &responseJson,
                                       const char *deviceXAddr,
                                       const char *userName,
                                       const char *password) override;
    virtual optional<string> getUsers(string &responseJson,
                                      const char *deviceXAddr,
                                      const char *userName,
                                      const char *password) override;
    virtual optional<string> getWsdlUrl(string &responseJson,
                                        const char *deviceXAddr) override;
    virtual optional<string> getDiscoveryMode(string &responseJson,
                                              const char *deviceXAddr,
                                              const char *userName,
                                              const char *password) override;
    virtual optional<string> getRemoteDiscoveryMode(string &responseJson,
                                                    const char *deviceXAddr,
                                                    const char *userName,
                                                    const char *password) override;
    virtual optional<string> setDNS(string &responseJson,
                                    const char *deviceXAddr,
                                    const char *userName,
                                    const char *password,
                                    ONVIF_SET_DNS_PARAM *param) override;
    virtual optional<string> setDynamicDNS(string &responseJson,
                                           const char *deviceXAddr,
                                           const char *userName,
                                           const char *password,
                                           ONVIF_SET_DYNAMIC_DNS_PARAM *param) override;
    virtual optional<string> setHostname(string &responseJson,
                                         const char *deviceXAddr,
                                         const char *userName,
                                         const char *password,
                                         const char *name) override;
    virtual optional<string> systemReboot(string &responseJson,
                                          const char *deviceXAddr,
                                          const char *userName,
                                          const char *password) override;
    virtual optional<string> setHostnameFromDHCP(string &responseJson,
                                                 const char *deviceXAddr,
                                                 const char *userName,
                                                 const char *password,
                                                 bool useDHCP) override;
    virtual optional<string> setUser(string &responseJson,
                                     const char *deviceXAddr,
                                     const char *userName,
                                     const char *password,
                                     ONVIF_SET_USER_PARAM *param) override;
    virtual optional<string> setScopes(string &responseJson,
                                       const char *deviceXAddr,
                                       const char *userName,
                                       const char *password,
                                       ONVIF_SET_SCOPES_PARAM *param) override;
    virtual optional<string> setRemoteUser(string &responseJson,
                                           const char *deviceXAddr,
                                           const char *userName,
                                           const char *password,
                                           ONVIF_SET_REMOTE_USER_PARAM *param) override;
    virtual optional<string> setDiscoveryMode(string &responseJson,
                                              const char *deviceXAddr,
                                              const char *userName,
                                              const char *password,
                                              bool enable) override;
    virtual optional<string> setRemoteDiscoveryMode(string &responseJson,
                                                    const char *deviceXAddr,
                                                    const char *userName,
                                                    const char *password,
                                                    bool enable) override;
    virtual optional<string> setNetworkDefaultGateway(string &responseJson,
                                                      const char *deviceXAddr,
                                                      const char *userName,
                                                      const char *password,
                                                      ONVIF_SET_NETWORK_DEFAULT_GATEWAY_PARAM *param) override;
    virtual optional<string> setNetworkInterfaces(string &responseJson,
                                                  const char *deviceXAddr,
                                                  const char *userName,
                                                  const char *password,
                                                  ONVIF_SET_NETWORK_INTERFACE_PARAM *param) override;
    virtual optional<string> setNetworkProtocols(string &responseJson,
                                                 const char *deviceXAddr,
                                                 const char *userName,
                                                 const char *password,
                                                 ONVIF_SET_NETWORK_PROTOCOLS_PARAM *param) override;

    virtual optional<string> getVideoSources_V1(string &responseJson,
                                                const char *deviceXAddr,
                                                const char *userName,
                                                const char *password) override;
    virtual optional<string> getVideoSourceConfigurations_V1(string &responseJson,
                                                             const char *deviceXAddr,
                                                             const char *userName,
                                                             const char *password) override;
    virtual optional<string> getVideoSourceConfiguration_V1(string &responseJson,
                                                            const char *deviceXAddr,
                                                            const char *userName,
                                                            const char *password,
                                                            const char *configurationToken) override;
    virtual optional<string> getVideoSourceConfigurationOptions_V1(string &responseJson,
                                                                   const char *deviceXAddr,
                                                                   const char *userName,
                                                                   const char *password,
                                                                   const char *configurationToken = nullptr,
                                                                   const char *profileToken = nullptr) override;
    virtual optional<string> getVideoSourceModes_V1(string &responseJson,
                                                    const char *deviceXAddr,
                                                    const char *userName,
                                                    const char *password,
                                                    const char *videoSourceToken) override;
    virtual optional<string> getVideoEncoderConfigurations_V1(string &responseJson,
                                                              const char *deviceXAddr,
                                                              const char *userName,
                                                              const char *password) override;
    virtual optional<string> getVideoEncoderConfiguration_V1(string &responseJson,
                                                             const char *deviceXAddr,
                                                             const char *userName,
                                                             const char *password,
                                                             const char *configurationToken) override;
    virtual optional<string> getVideoEncoderConfigurationOptions_V1(string &responseJson,
                                                                    const char *deviceXAddr,
                                                                    const char *userName,
                                                                    const char *password,
                                                                    const char *configurationToken = nullptr,
                                                                    const char *profileToken = nullptr) override;
    virtual optional<string> getAudioSources_V1(string &responseJson,
                                                const char *deviceXAddr,
                                                const char *userName,
                                                const char *password) override;
    virtual optional<string> getAudioSourceConfigurations_V1(string &responseJson,
                                                             const char *deviceXAddr,
                                                             const char *userName,
                                                             const char *password) override;
    virtual optional<string> getAudioSourceConfiguration_V1(string &responseJson,
                                                            const char *deviceXAddr,
                                                            const char *userName,
                                                            const char *password,
                                                            const char *configurationToken) override;
    virtual optional<string> getAudioSourceConfigurationOptions_V1(string &responseJson,
                                                                   const char *deviceXAddr,
                                                                   const char *userName,
                                                                   const char *password,
                                                                   const char *configurationToken = nullptr,
                                                                   const char *profileToken = nullptr) override;
    virtual optional<string> getAudioOutputs_V1(string &responseJson,
                                                const char *deviceXAddr,
                                                const char *userName,
                                                const char *password) override;
    virtual optional<string> getAudioOutputConfigurations_V1(string &responseJson,
                                                             const char *deviceXAddr,
                                                             const char *userName,
                                                             const char *password) override;
    virtual optional<string> getAudioOutputConfiguration_V1(string &responseJson,
                                                            const char *deviceXAddr,
                                                            const char *userName,
                                                            const char *password,
                                                            const char *configurationToken) override;
    virtual optional<string> getAudioOutputConfigurationOptions_V1(string &responseJson,
                                                                   const char *deviceXAddr,
                                                                   const char *userName,
                                                                   const char *password,
                                                                   const char *configurationToken = nullptr,
                                                                   const char *profileToken = nullptr) override;
    virtual optional<string> getAudioEncoderConfigurations_V1(string &responseJson,
                                                              const char *deviceXAddr,
                                                              const char *userName,
                                                              const char *password) override;
    virtual optional<string> getAudioEncoderConfiguration_V1(string &responseJson,
                                                             const char *deviceXAddr,
                                                             const char *userName,
                                                             const char *password,
                                                             const char *configurationToken) override;
    virtual optional<string> getAudioEncoderConfigurationOptions_V1(string &responseJson,
                                                                    const char *deviceXAddr,
                                                                    const char *userName,
                                                                    const char *password,
                                                                    const char *configurationToken = nullptr,
                                                                    const char *profileToken = nullptr) override;
    virtual optional<string> getAudioDecoderConfigurations_V1(string &responseJson,
                                                              const char *deviceXAddr,
                                                              const char *userName,
                                                              const char *password) override;
    virtual optional<string> getAudioDecoderConfiguration_V1(string &responseJson,
                                                             const char *deviceXAddr,
                                                             const char *userName,
                                                             const char *password,
                                                             const char *configurationToken) override;
    virtual optional<string> getAudioDecoderConfigurationOptions_V1(string &responseJson,
                                                                    const char *deviceXAddr,
                                                                    const char *userName,
                                                                    const char *password,
                                                                    const char *configurationToken = nullptr,
                                                                    const char *profileToken = nullptr) override;
    virtual optional<string> getMetadataConfigurations_V1(string &responseJson,
                                                          const char *deviceXAddr,
                                                          const char *userName,
                                                          const char *password) override;
    virtual optional<string> getMetadataConfiguration_V1(string &responseJson,
                                                         const char *deviceXAddr,
                                                         const char *userName,
                                                         const char *password,
                                                         const char *configurationToken) override;
    virtual optional<string> getMetadataConfigurationOptions_V1(string &responseJson,
                                                                const char *deviceXAddr,
                                                                const char *userName,
                                                                const char *password,
                                                                const char *configurationToken = nullptr,
                                                                const char *profileToken = nullptr) override;
    virtual optional<string> getVideoAnalyticsConfigurations_V1(string &responseJson,
                                                                const char *deviceXAddr,
                                                                const char *userName,
                                                                const char *password) override;
    virtual optional<string> getVideoAnalyticsConfiguration_V1(string &responseJson,
                                                               const char *deviceXAddr,
                                                               const char *userName,
                                                               const char *password,
                                                               const char *configurationToken) override;
    virtual optional<string> getProfiles_V1(string &responseJson,
                                            const char *deviceXAddr,
                                            const char *userName,
                                            const char *password) override;
    virtual optional<string> getProfile_V1(string &responseJson,
                                           const char *deviceXAddr,
                                           const char *userName,
                                           const char *password,
                                           const char *profileToken) override;
    virtual optional<string> createProfile_V1(string &responseJson,
                                              const char *deviceXAddr,
                                              const char *userName,
                                              const char *password,
                                              const char *name,
                                              const char *profileToken = nullptr) override;
    virtual optional<string> deleteProfile_V1(string &responseJson,
                                              const char *deviceXAddr,
                                              const char *userName,
                                              const char *password,
                                              const char *profileToken) override;
    virtual optional<string> getOSDs_V1(string &responseJson,
                                        const char *deviceXAddr,
                                        const char *userName,
                                        const char *password,
                                        const char *videoSourceConfigurationToken = nullptr) override;
    virtual optional<string> getOSD_V1(string &responseJson,
                                       const char *deviceXAddr,
                                       const char *userName,
                                       const char *password,
                                       const char *configurationToken) override;
    virtual optional<string> getOSDOptions_V1(string &responseJson,
                                              const char *deviceXAddr,
                                              const char *userName,
                                              const char *password,
                                              const char *videoSourceConfigurationToken) override;
    virtual optional<string> createOSD_V1(string &responseJson,
                                          const char *deviceXAddr,
                                          const char *userName,
                                          const char *password,
                                          ONVIF_SET_OSD_PARAM *param) override;
    virtual optional<string> deleteOSD_V1(string &responseJson,
                                          const char *deviceXAddr,
                                          const char *userName,
                                          const char *password,
                                          const char *configurationToken) override;
    virtual optional<string> setOSD_V1(string &responseJson,
                                       const char *deviceXAddr,
                                       const char *userName,
                                       const char *password,
                                       ONVIF_SET_OSD_PARAM *param) override;
    virtual optional<string> getStreamUri_V1(string &responseJson,
                                             const char *deviceXAddr,
                                             const char *userName,
                                             const char *password,
                                             const char *profileToken,
                                             ONVIF_STREAM_SETUP_PARAM *streamSetup) override;
    virtual optional<string> getSnapshotUri_V1(string &responseJson,
                                               const char *deviceXAddr,
                                               const char *userName,
                                               const char *password,
                                               const char *profileToken) override;
    virtual optional<string> startMulticastStreaming_V1(string &responseJson,
                                                        const char *deviceXAddr,
                                                        const char *userName,
                                                        const char *password,
                                                        const char *profileToken) override;
    virtual optional<string> stopMulticastStreaming_V1(string &responseJson,
                                                       const char *deviceXAddr,
                                                       const char *userName,
                                                       const char *password,
                                                       const char *profileToken) override;
    virtual optional<string> addVideoSourceConfiguration_V1(string &responseJson,
                                                            const char *deviceXAddr,
                                                            const char *userName,
                                                            const char *password,
                                                            const char *configurationToken,
                                                            const char *profileToken) override;
    virtual optional<string> removeVideoSourceConfiguration_V1(string &responseJson,
                                                               const char *deviceXAddr,
                                                               const char *userName,
                                                               const char *password,
                                                               const char *profileToken) override;
    virtual optional<string> addVideoEncoderConfiguration_V1(string &responseJson,
                                                             const char *deviceXAddr,
                                                             const char *userName,
                                                             const char *password,
                                                             const char *configurationToken,
                                                             const char *profileToken) override;
    virtual optional<string> removeVideoEncoderConfiguration_V1(string &responseJson,
                                                                const char *deviceXAddr,
                                                                const char *userName,
                                                                const char *password,
                                                                const char *profileToken) override;
    virtual optional<string> addAudioSourceConfiguration_V1(string &responseJson,
                                                            const char *deviceXAddr,
                                                            const char *userName,
                                                            const char *password,
                                                            const char *configurationToken,
                                                            const char *profileToken) override;
    virtual optional<string> removeAudioSourceConfiguration_V1(string &responseJson,
                                                               const char *deviceXAddr,
                                                               const char *userName,
                                                               const char *password,
                                                               const char *profileToken) override;
    virtual optional<string> addAudioOutputConfiguration_V1(string &responseJson,
                                                            const char *deviceXAddr,
                                                            const char *userName,
                                                            const char *password,
                                                            const char *configurationToken,
                                                            const char *profileToken) override;
    virtual optional<string> removeAudioOutputConfiguration_V1(string &responseJson,
                                                               const char *deviceXAddr,
                                                               const char *userName,
                                                               const char *password,
                                                               const char *profileToken) override;
    virtual optional<string> addAudioEncoderConfiguration_V1(string &responseJson,
                                                             const char *deviceXAddr,
                                                             const char *userName,
                                                             const char *password,
                                                             const char *configurationToken,
                                                             const char *profileToken) override;
    virtual optional<string> removeAudioEncoderConfiguration_V1(string &responseJson,
                                                                const char *deviceXAddr,
                                                                const char *userName,
                                                                const char *password,
                                                                const char *profileToken) override;
    virtual optional<string> addAudioDecoderConfiguration_V1(string &responseJson,
                                                             const char *deviceXAddr,
                                                             const char *userName,
                                                             const char *password,
                                                             const char *configurationToken,
                                                             const char *profileToken) override;
    virtual optional<string> removeAudioDecoderConfiguration_V1(string &responseJson,
                                                                const char *deviceXAddr,
                                                                const char *userName,
                                                                const char *password,
                                                                const char *profileToken) override;
    virtual optional<string> addMetadataConfiguration_V1(string &responseJson,
                                                         const char *deviceXAddr,
                                                         const char *userName,
                                                         const char *password,
                                                         const char *configurationToken,
                                                         const char *profileToken) override;
    virtual optional<string> removeMetadataConfiguration_V1(string &responseJson,
                                                            const char *deviceXAddr,
                                                            const char *userName,
                                                            const char *password,
                                                            const char *profileToken) override;
    virtual optional<string> addVideoAnalyticsConfiguration_V1(string &responseJson,
                                                               const char *deviceXAddr,
                                                               const char *userName,
                                                               const char *password,
                                                               const char *configurationToken,
                                                               const char *profileToken) override;
    virtual optional<string> removeVideoAnalyticsConfiguration_V1(string &responseJson,
                                                                  const char *deviceXAddr,
                                                                  const char *userName,
                                                                  const char *password,
                                                                  const char *profileToken) override;
    virtual optional<string> addPTZConfiguration_V1(string &responseJson,
                                                    const char *deviceXAddr,
                                                    const char *userName,
                                                    const char *password,
                                                    const char *configurationToken,
                                                    const char *profileToken) override;
    virtual optional<string> removePTZConfiguration_V1(string &responseJson,
                                                       const char *deviceXAddr,
                                                       const char *userName,
                                                       const char *password,
                                                       const char *profileToken) override;
    virtual optional<string> getVideoSourceConfigurations_V2(string &responseJson,
                                                             const char *deviceXAddr,
                                                             const char *userName,
                                                             const char *password,
                                                             const char *configurationToken = nullptr,
                                                             const char *profileToken = nullptr) override;
    virtual optional<string> getVideoSourceConfigurationOptions_V2(string &responseJson,
                                                                   const char *deviceXAddr,
                                                                   const char *userName,
                                                                   const char *password,
                                                                   const char *configurationToken = nullptr,
                                                                   const char *profileToken = nullptr) override;
    virtual optional<string> getVideoSourceModes_V2(string &responseJson,
                                                    const char *deviceXAddr,
                                                    const char *userName,
                                                    const char *password,
                                                    const char *videoSourceToken) override;
    virtual optional<string> getVideoEncoderInstances_V2(string &responseJson,
                                                         const char *deviceXAddr,
                                                         const char *userName,
                                                         const char *password,
                                                         const char *videoSourceConfigurationToken) override;
    virtual optional<string> getVideoEncoderConfigurations_V2(string &responseJson,
                                                              const char *deviceXAddr,
                                                              const char *userName,
                                                              const char *password,
                                                              const char *configurationToken = nullptr,
                                                              const char *profileToken = nullptr) override;
    virtual optional<string> getVideoEncoderConfigurationOptions_V2(string &responseJson,
                                                                    const char *deviceXAddr,
                                                                    const char *userName,
                                                                    const char *password,
                                                                    const char *configurationToken = nullptr,
                                                                    const char *profileToken = nullptr) override;
    virtual optional<string> getAudioSourceConfigurations_V2(string &responseJson,
                                                             const char *deviceXAddr,
                                                             const char *userName,
                                                             const char *password,
                                                             const char *configurationToken = nullptr,
                                                             const char *profileToken = nullptr) override;
    virtual optional<string> getAudioSourceConfigurationOptions_V2(string &responseJson,
                                                                   const char *deviceXAddr,
                                                                   const char *userName,
                                                                   const char *password,
                                                                   const char *configurationToken = nullptr,
                                                                   const char *profileToken = nullptr) override;
    virtual optional<string> getAudioOutputConfigurations_V2(string &responseJson,
                                                             const char *deviceXAddr,
                                                             const char *userName,
                                                             const char *password,
                                                             const char *configurationToken = nullptr,
                                                             const char *profileToken = nullptr) override;
    virtual optional<string> getAudioOutputConfigurationOptions_V2(string &responseJson,
                                                                   const char *deviceXAddr,
                                                                   const char *userName,
                                                                   const char *password,
                                                                   const char *configurationToken = nullptr,
                                                                   const char *profileToken = nullptr) override;
    virtual optional<string> getAudioEncoderConfigurations_V2(string &responseJson,
                                                              const char *deviceXAddr,
                                                              const char *userName,
                                                              const char *password,
                                                              const char *configurationToken = nullptr,
                                                              const char *profileToken = nullptr) override;
    virtual optional<string> getAudioEncoderConfigurationOptions_V2(string &responseJson,
                                                                    const char *deviceXAddr,
                                                                    const char *userName,
                                                                    const char *password,
                                                                    const char *configurationToken = nullptr,
                                                                    const char *profileToken = nullptr) override;
    virtual optional<string> getAudioDecoderConfigurations_V2(string &responseJson,
                                                              const char *deviceXAddr,
                                                              const char *userName,
                                                              const char *password,
                                                              const char *configurationToken = nullptr,
                                                              const char *profileToken = nullptr) override;
    virtual optional<string> getAudioDecoderConfigurationOptions_V2(string &responseJson,
                                                                    const char *deviceXAddr,
                                                                    const char *userName,
                                                                    const char *password,
                                                                    const char *configurationToken = nullptr,
                                                                    const char *profileToken = nullptr) override;
    virtual optional<string> getMetadataConfigurations_V2(string &responseJson,
                                                          const char *deviceXAddr,
                                                          const char *userName,
                                                          const char *password,
                                                          const char *configurationToken = nullptr,
                                                          const char *profileToken = nullptr) override;
    virtual optional<string> getMetadataConfigurationOptions_V2(string &responseJson,
                                                                const char *deviceXAddr,
                                                                const char *userName,
                                                                const char *password,
                                                                const char *configurationToken = nullptr,
                                                                const char *profileToken = nullptr) override;
    virtual optional<string> getAnalyticsConfigurations_V2(string &responseJson,
                                                           const char *deviceXAddr,
                                                           const char *userName,
                                                           const char *password,
                                                           const char *configurationToken = nullptr,
                                                           const char *profileToken = nullptr) override;
    virtual optional<string> getProfiles_V2(string &responseJson,
                                            const char *deviceXAddr,
                                            const char *userName,
                                            const char *password,
                                            const char *profileToken = nullptr,
                                            ONVIF_CONFIGURATION_ENUMERATION *type = nullptr) override;
    virtual optional<string> createProfile_V2(string &responseJson,
                                              const char *deviceXAddr,
                                              const char *userName,
                                              const char *password,
                                              const char *name) override;
    virtual optional<string> deleteProfile_V2(string &responseJson,
                                              const char *deviceXAddr,
                                              const char *userName,
                                              const char *password,
                                              const char *profileToken) override;
    virtual optional<string> getOSDs_V2(string &responseJson,
                                        const char *deviceXAddr,
                                        const char *userName,
                                        const char *password,
                                        const char *videoSourceConfigurationToken = nullptr,
                                        const char *OSDToken = nullptr) override;
    virtual optional<string> getOSDOptions_V2(string &responseJson,
                                              const char *deviceXAddr,
                                              const char *userName,
                                              const char *password,
                                              const char *videoSourceConfigurationToken) override;
    virtual optional<string> createOSD_V2(string &responseJson,
                                          const char *deviceXAddr,
                                          const char *userName,
                                          const char *password,
                                          ONVIF_SET_OSD_PARAM *param) override;
    virtual optional<string> deleteOSD_V2(string &responseJson,
                                          const char *deviceXAddr,
                                          const char *userName,
                                          const char *password,
                                          const char *configurationToken) override;
    virtual optional<string> setOSD_V2(string &responseJson,
                                       const char *deviceXAddr,
                                       const char *userName,
                                       const char *password,
                                       ONVIF_SET_OSD_PARAM *param) override;
    virtual optional<string> getMasks_V2(string &responseJson,
                                         const char *deviceXAddr,
                                         const char *userName,
                                         const char *password,
                                         const char *videoSourceConfigurationToken = nullptr,
                                         const char *maskToken = nullptr) override;
    virtual optional<string> getMaskOptions_V2(string &responseJson,
                                               const char *deviceXAddr,
                                               const char *userName,
                                               const char *password,
                                               const char *videoSourceConfigurationToken) override;
    virtual optional<string> getStreamUri_V2(string &responseJson,
                                             const char *deviceXAddr,
                                             const char *userName,
                                             const char *password,
                                             const char *profileToken,
                                             ONVIF_TRANSPORT_PROTOCOL_V2 protocol) override;
    virtual optional<string> getSnapshotUri_V2(string &responseJson,
                                               const char *deviceXAddr,
                                               const char *userName,
                                               const char *password,
                                               const char *profileToken) override;
    virtual optional<string> startMulticastStreaming_V2(string &responseJson,
                                                        const char *deviceXAddr,
                                                        const char *userName,
                                                        const char *password,
                                                        const char *profileToken) override;
    virtual optional<string> stopMulticastStreaming_V2(string &responseJson,
                                                       const char *deviceXAddr,
                                                       const char *userName,
                                                       const char *password,
                                                       const char *profileToken) override;
    virtual optional<string> addConfiguration_V2(string &responseJson,
                                                 const char *deviceXAddr,
                                                 const char *userName,
                                                 const char *password,
                                                 const char *profileToken,
                                                 ONVIF_CONFIGURATION_ENUMERATION *configurations) override;
    virtual optional<string> removeConfiguration_V2(string &responseJson,
                                                    const char *deviceXAddr,
                                                    const char *userName,
                                                    const char *password,
                                                    const char *profileToken,
                                                    ONVIF_CONFIGURATION_ENUMERATION *configurations) override;
    virtual optional<string> getVideoOutputs_DeviceIO(string &responseJson,
                                                      const char *deviceXAddr,
                                                      const char *userName,
                                                      const char *password) override;
    virtual optional<string> getVideoSources_DeviceIO(string &responseJson,
                                                      const char *deviceXAddr,
                                                      const char *userName,
                                                      const char *password) override;
    virtual optional<string> getVideoOutputConfiguration_DeviceIO(string &responseJson,
                                                                  const char *deviceXAddr,
                                                                  const char *userName,
                                                                  const char *password,
                                                                  const char *videoOutputToken) override;
    virtual optional<string> getVideoOutputConfigurationOptions_DeviceIO(string &responseJson,
                                                                         const char *deviceXAddr,
                                                                         const char *userName,
                                                                         const char *password,
                                                                         const char *videoOutputToken) override;
    virtual optional<string> getVideoSourceConfiguration_DeviceIO(string &responseJson,
                                                                  const char *deviceXAddr,
                                                                  const char *userName,
                                                                  const char *password,
                                                                  const char *videoSourceToken) override;
    virtual optional<string> getVideoSourceConfigurationOptions_DeviceIO(string &responseJson,
                                                                         const char *deviceXAddr,
                                                                         const char *userName,
                                                                         const char *password,
                                                                         const char *videoSourceToken) override;
    virtual optional<string> getAudioOutputs_DeviceIO(string &responseJson,
                                                      const char *deviceXAddr,
                                                      const char *userName,
                                                      const char *password) override;
    virtual optional<string> getAudioSources_DeviceIO(string &responseJson,
                                                      const char *deviceXAddr,
                                                      const char *userName,
                                                      const char *password) override;
    virtual optional<string> getAudioOutputConfiguration_DeviceIO(string &responseJson,
                                                                  const char *deviceXAddr,
                                                                  const char *userName,
                                                                  const char *password,
                                                                  const char *audioOutputToken) override;
    virtual optional<string> getAudioOutputConfigurationOptions_DeviceIO(string &responseJson,
                                                                         const char *deviceXAddr,
                                                                         const char *userName,
                                                                         const char *password,
                                                                         const char *audioOutputToken) override;
    virtual optional<string> getAudioSourceConfiguration_DeviceIO(string &responseJson,
                                                                  const char *deviceXAddr,
                                                                  const char *userName,
                                                                  const char *password,
                                                                  const char *audioSourceToken) override;
    virtual optional<string> getAudioSourceConfigurationOptions_DeviceIO(string &responseJson,
                                                                         const char *deviceXAddr,
                                                                         const char *userName,
                                                                         const char *password,
                                                                         const char *audioSourceToken) override;

    virtual optional<string> getNodes(string &responseJson,
                                      const char *deviceXAddr,
                                      const char *userName,
                                      const char *password) override;
    virtual optional<string> getNode(string &responseJson,
                                     const char *deviceXAddr,
                                     const char *userName,
                                     const char *password,
                                     const char *nodeToken) override;
    virtual optional<string> getPTZConfigurations(string &responseJson,
                                                  const char *deviceXAddr,
                                                  const char *userName,
                                                  const char *password) override;
    virtual optional<string> getPTZConfiguration(string &responseJson,
                                                 const char *deviceXAddr,
                                                 const char *userName,
                                                 const char *password,
                                                 const char *configurationToken) override;
    virtual optional<string> getPTZConfigurationOptions(string &responseJson,
                                                        const char *deviceXAddr,
                                                        const char *userName,
                                                        const char *password,
                                                        const char *configurationToken) override;
    virtual optional<string> getPTZStatus(string &responseJson,
                                          const char *deviceXAddr,
                                          const char *userName,
                                          const char *password,
                                          const char *profileToken) override;
    virtual optional<string> absoluteMove(string &responseJson,
                                          const char *deviceXAddr,
                                          const char *userName,
                                          const char *password,
                                          const char *profileToken,
                                          ONVIF_PTZ_MOVE_PARAM *move) override;
    virtual optional<string> relativeMove(string &responseJson,
                                          const char *deviceXAddr,
                                          const char *userName,
                                          const char *password,
                                          const char *profileToken,
                                          ONVIF_PTZ_MOVE_PARAM *move) override;
    virtual optional<string> continuousMove(string &responseJson,
                                            const char *deviceXAddr,
                                            const char *userName,
                                            const char *password,
                                            const char *profileToken,
                                            ONVIF_PTZ_SPEED_PARAM *speed,
                                            const char *timeOutDuration = nullptr) override;
    virtual optional<string> stopMove(string &responseJson,
                                      const char *deviceXAddr,
                                      const char *userName,
                                      const char *password,
                                      const char *profileToken,
                                      bool panTilt = true,
                                      bool zoom = true) override;
    virtual optional<string> getPresets(string &responseJson,
                                        const char *deviceXAddr,
                                        const char *userName,
                                        const char *password,
                                        const char *profileToken) override;
    virtual optional<string> gotoHomePosition(string &responseJson,
                                              const char *deviceXAddr,
                                              const char *userName,
                                              const char *password,
                                              const char *profileToken,
                                              ONVIF_PTZ_SPEED_PARAM *speed = nullptr) override;
    virtual optional<string> setHomePosition(string &responseJson,
                                             const char *deviceXAddr,
                                             const char *userName,
                                             const char *password,
                                             const char *profileTokenr) override;
    virtual optional<string> gotoPreset(string &responseJson,
                                        const char *deviceXAddr,
                                        const char *userName,
                                        const char *password,
                                        const char *profileToken,
                                        const char *presetToken,
                                        ONVIF_PTZ_SPEED_PARAM *speed = nullptr) override;
    virtual optional<string> setPreset(string &responseJson,
                                       const char *deviceXAddr,
                                       const char *userName,
                                       const char *password,
                                       const char *profileToken,
                                       const char *presetToken,
                                       const char *presetName = nullptr) override;
    virtual optional<string> addPreset(string &responseJson,
                                       const char *deviceXAddr,
                                       const char *userName,
                                       const char *password,
                                       const char *profileToken,
                                       const char *presetName) override;
    virtual optional<string> removePreset(string &responseJson,
                                          const char *deviceXAddr,
                                          const char *userName,
                                          const char *password,
                                          const char *profileToken,
                                          const char *presetToken) override;

    virtual optional<string> getRecordingSummary(string &responseJson,
                                                 const char *deviceXAddr,
                                                 const char *userName,
                                                 const char *password) override;
    virtual optional<string> findRecordings(string &responseJson,
                                            const char *deviceXAddr,
                                            const char *userName,
                                            const char *password,
                                            ONVIF_FIND_RECORDINGS_PARAM *param) override;
    virtual optional<string> getRecordingInformation(string &responseJson,
                                                     const char *deviceXAddr,
                                                     const char *userName,
                                                     const char *password,
                                                     const char *recordingToken) override;
    virtual optional<string> getRecordingSearchResults(string &responseJson,
                                                       const char *deviceXAddr,
                                                       const char *userName,
                                                       const char *password,
                                                       const char *searchToken,
                                                       const int *minResults = nullptr,
                                                       const int *maxResults = nullptr,
                                                       const char *waitDuration = nullptr) override;
    virtual optional<string> endSearch(string &responseJson,
                                       const char *deviceXAddr,
                                       const char *userName,
                                       const char *password,
                                       const char *searchTokenr) override;

    virtual optional<string> getReplayUri(string &responseJson,
                                          const char *deviceXAddr,
                                          const char *userName,
                                          const char *password,
                                          const char *recordingToken,
                                          ONVIF_STREAM_SETUP_PARAM *streamSetup) override;

    virtual optional<string> focusMove(string &responseJson,
                                       const char *deviceXAddr,
                                       const char *userName,
                                       const char *password,
                                       const char *videoSourceToken,
                                       ONVIF_FOCUS_MOVE_PARAM *moveParam) override;
    virtual optional<string> stopFocusMove(string &responseJson,
                                           const char *deviceXAddr,
                                           const char *userName,
                                           const char *password,
                                           const char *videoSourceToken) override;

    virtual optional<string> focusMove_Imaging(string &responseJson,
                                               const char *deviceXAddr,
                                               const char *userName,
                                               const char *password,
                                               const char *videoSourceToken,
                                               float focusSpeed) override;
    virtual optional<string> stopFocusMove_Imaging(string &responseJson,
                                                   const char *deviceXAddr,
                                                   const char *userName,
                                                   const char *password,
                                                   const char *videoSourceToken) override;

private:
    optional<string> getIpList();
    soap *newSoap();
    void deleteSoap(soap *soapPtr);
    string printError(soap *soapPtr, string errorPrefix);
    void log(string message, int logLevel = -1);
    string makeErrorStr(string errorPrefix, string err);
    optional<string> setAuthInfo(soap *soapPtr, const char *username, const char *password);
    optional<string> listenHello(listenCB cb, void *pUserData, const char *interfaceAddr);
    optional<string> listenBye(listenCB cb, void *pUserData, const char *interfaceAddr);
    void listenHelloThread(soap *soapPtr, listenCB cb, void *pUserData);
    void listenByeThread(soap *soapPtr, listenCB cb, void *pUserData);

private:
    void buildGetServiceCapabilitiesJsonStr(string &responseJson, _tds__GetServiceCapabilitiesResponse &response);

private:
    int listenHelloFlag;
    int listenByeFlag;
    int timeOut;
    vector<string> ipList;
    onvifToolUtils utils;
    const string *UUID;
    logCB cb_;
    void *logUserData;
};